package es.unex.meigas.ww.core;

import javax.swing.JDialog;

import org.geotools.referencing.crs.DefaultGeographicCRS;

import es.unex.meigas.dataObjects.IRasterLayer;
import es.unex.meigas.dataObjects.ITable;
import es.unex.meigas.dataObjects.IVectorLayer;
import es.unex.meigas.dataObjects.OutputFactory;
import es.unex.meigas.exceptions.UnsupportedOutputChannelException;
import es.unex.meigas.dataObjects.FileOutputChannel;
import es.unex.meigas.dataObjects.IOutputChannel;
import es.unex.meigas.rasterWrappers.GridExtent;
import es.unex.meigas.ww.core.WWRasterLayer;
import es.unex.meigas.ww.core.WWTable;
import es.unex.meigas.ww.core.WWVectorLayer;

public class WWOutputFactory extends OutputFactory {

	public IVectorLayer getNewVectorLayer(String sName,
										  int iShapeType,
										  Class[] types,
										  String[] sFields,
										  IOutputChannel channel,
										  Object crs)
				throws UnsupportedOutputChannelException {

		if (channel instanceof FileOutputChannel){
			String sFilename = ((FileOutputChannel)channel).getFilename();
			WWVectorLayer vectorLayer = new WWVectorLayer();
			vectorLayer.create(sName, iShapeType, types, sFields, sFilename, crs);
			return vectorLayer;
		}
		else{
			throw new UnsupportedOutputChannelException();
		}

	}

	public IRasterLayer getNewRasterLayer(String sName,
											int iDataType,
											GridExtent extent,
											int iBands,
											IOutputChannel channel,
											Object crs)
				throws UnsupportedOutputChannelException {

		if (channel instanceof FileOutputChannel){
			String sFilename = ((FileOutputChannel)channel).getFilename();
			WWRasterLayer layer = new WWRasterLayer();
			layer.create(sName, sFilename, extent, iDataType, iBands, crs);
			return layer;
		}
		else{
			throw new UnsupportedOutputChannelException();
		}

	}

	public ITable getNewTable(String sName, Class types[],
								String[] sFields, IOutputChannel channel)
					throws UnsupportedOutputChannelException {

		if (channel instanceof FileOutputChannel){
			String sFilename = ((FileOutputChannel)channel).getFilename();
			WWTable table = new WWTable();
			table.create(sName, sFilename, types, sFields);
			return table;
		}
		else{
			throw new UnsupportedOutputChannelException();
		}

	}

	protected String getTempFolder() {

		return System.getProperty("java.io.tmpdir");

	}

	public String[] getRasterLayerOutputExtensions() {

		return new String[]{"tif"};

	}

	public String[] getVectorLayerOutputExtensions() {

		return new String[]{"shp"};

	}

	public String[] getTableOutputExtensions() {

		return new String[]{"dbf"};

	}

	public Object getDefaultCRS() {

		return DefaultGeographicCRS.WGS84;

	}

}
